/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package matching_algorithms;

import algos.HungarianAlgorithm;
import com.jme3.math.Vector3f;
import java.util.ArrayList;
import java.util.Arrays;

import camera.AbstractCamera;

/**
 *
 * @author Moamen Mokhtar
 */
public class HungarianMatching extends AbstractMatching {
    
    public int[] match(float[][] g) {
        int[][] a = new HungarianAlgorithm().computeAssignments(g);
        int[] res = new int[g.length];
        Arrays.fill(res, -1);
        for (int i = 0; i < g[0].length; i++)
            if (a[i][0] != -1)
                res[a[i][0]] = a[i][1];
        return res;
    }

    @Override
    public float[][] buildGraph(ArrayList<AbstractCamera> cameras,ArrayList<Vector3f> positions,boolean [][] isMatched) {
        float[][] g = new float[cameras.size()][positions.size()];
        for (int i = 0; i < cameras.size(); i++) {
            for (int j = 0; j < positions.size(); j++) {
//                g[i][j] = (isMatched[i][j])
//                        ? cameras.get(i).getLocation().distance(positions.get(j)) : (1 << 30);
            	if(isMatched[i][j])
            		g[i][j] = cameras.get(i).getLocation().distance(positions.get(j));
            	else
            		g[i][j] = 1<<30;
            }
        }
        return g;
    }
}
